<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cmcc.operator.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<% 
	String flag = request.getParameter("flag");
	if(flag!=null&&flag.equals("login")){
		String operator_id = request.getParameter("userid");
		String operator_pwd = request.getParameter("passwd");
		
		if(Operator.checklogin(operator_id, operator_pwd)){
			System.out.println("用户名密码正确----login。。。");
			session.setAttribute("login", "yes");
			Operator o = Operator.getOperatorById(operator_id);
			o.print();
			session.setAttribute("operator", o);
			response.sendRedirect("frameSet/frameSet.jsp");
			return;
		}else{
		%>
			<<script type="text/javascript">
			<!--
				alert("用户名或密码错误");
			//-->
			</script>
		<%
		}
		
	}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'login.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link href="style/stylet.css" rel="stylesheet" type="text/css">
  </head>
<script type="text/javascript">
	var flag = 0;
   function checknull(form){
   		var userid = form.userid.value;
   		var password = form.passwd.value;
   		if(userid===""||password===""){
   			alert("用户名或密码不能为空");
   			return false;
   		}
   		if(flag==1){   		
   			//alert(flag);	
   			return true;
   		}
   		return false;
   }

     var xmlHttp;
	function createXMLHttpRequest() {
		if (window.ActiveXObject) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else if (window.XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		}
	}

	function createQueryString() {
		var userid = document.getElementByIdx_x("userid").value;
		var queryString = "userid=" + userid;
		return queryString ;
	}
	
	function checkauth() {
		 
		var authcode = document.getElementById("authcode").value;
		//alert(authcode);
		createXMLHttpRequest();
		xmlHttp.onreadystatechange = handleStateChange;
		var url="servlet/checkauth?";
		xmlHttp.open("GET", url+"authcode="+authcode, true);
		xmlHttp.send(null);
			
	}
	function handleStateChange() {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				var Data = xmlHttp.responseText;
                //alert(Data);
                var str = Data.substring(0, 2);
                //alert(str);
                if(str==="NO"){
                	alert("验证码错误！");
                	flag=0;
                }else if(str==="OK"){
                	flag=1;
                }
			}
		}
	}
 
</script>  
  <body>
	&nbsp;
		<div id="box1">
		&nbsp;
			<div id="tab_box">
				<form action="login.jsp" method="post" name="login"
					onsubmit="return checknull(this);">
					<span class="denglu_font_title">欢迎登录</span>
					<br />
					<br />
					<label for="userid" class="yonghuming_font">
						用户：
					</label>
					<input name="userid" type="text" id="userid" accesskey="n"
						tabindex="1"
						style="font-family: '宋体'; font-size: 12px; color: #575757" />
					<br />
					<br />
					<label for="passwd" class="yonghuming_font">
						密码：
					</label>
					<input name="passwd" type="password" id="passwd" tabindex="2"
						style="font-family: '宋体'; font-size: 12px; color: #575757" />
					<br />
					<br />
					<label for="passwd" class="yonghuming_font">
						验证码:
					</label>
					<input type="text" name="codepic" maxlength="10" id="authcode"
						tabindex="3" onblur="checkauth();"
						style="font-family: '宋体'; font-size: 12px; color: #575757" />
					<br>
					
					<img alt= "验证码" src="authcode/authCodeImage.jsp" id ="code">
					<script type= "text/javascript">
					       function reload(){
					              document.getElementById( "code").setAttribute("src" ,"authcode/authCodeImage.jsp?a="+new Date().getTime());
					       }
					</script>
					<a href= "javascript:reload()">
					        <font size= 2 color ="green"> 看不清楚，换一张 </font>
					</a>

					<br />
					<input name="denglu_tijiao" type="submit" id="denglu_tijiao"
						tabindex="3" value="确认" />
					<input name="denglu_chongzi" type="reset" id="denglu_reset"
						tabindex="4" value="重置" />
					<input type="hidden" name="flag" value="login">
				</form>
				<font color='red'>  </font>

			</div>

		</div>

	</body>
</html>
